// import { SortOrder } from 'antd/lib/table/interface';
import { request } from 'umi';
import type { QueryParams } from './data';

export async function getList(params: { current?: number; pageSize?: number; name?: string }) {
  const res = await request('/app/links', {
    params: {
      page: params.current,
      pageSize: params.pageSize,
      name: params.name,
    },
  });

  if (res.code === 0) {
    return { success: true, data: res.data.list, total: res.data.pagination.total };
  }
  return { success: false, data: [], total: 0 };
}

export async function addAppLinks(data: QueryParams) {
  const res = await request('/app/links', {
    method: 'POST',
    data: { ...data },
  });
  if (res.code == 0) {
    return { success: true };
  }
  return null;
}

//获取小程序链接
export async function getApplinksByid(id: string) {
  const res = await request(`/app/links/${id}`, {
    method: 'GET',
  });
  if (res.code == 0) {
    return { success: true, data: res.data };
  }
  return { success: false, data: [] };
}

export async function uploadIcon() {
  const res = await request('/oss/upload/singleImage');
  if (res.code == 0) {
    return res;
  }
}

export async function deleteLinksItemByid(id: string) {
  const res = await request(`/app/links/${id}`, {
    method: 'DELETE',
  });

  if (res.code == 0) {
    return { success: true };
  }
  return null;
  // return {success: false}
}

export async function updateAppLinks(id: string, data: QueryParams) {
  const res = await request(`/app/links/${id}`, {
    method: 'PUT',
    data: { ...data },
  });
  if (res.code == 0) {
    return { success: true };
  }
  return null;
}
